﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using DeSleeper.Client.Framework;

namespace DeSleeper.Client.WakeUp
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class WakeUpView : PageViewBase<WakeUpViewModel>
    {
        public WakeUpView()
        {
            InitializeComponent();
        }

        private void targetChanged(object sender, SelectionChangedEventArgs e)
        {
            var target = targetComputer.SelectedItem as TargetComputer;
            if (wakeUpMethod != null)
            {
                foreach (var method in wakeUpMethod.Items.OfType<WakeUpMethod>())
                    method.Target = target;

                if (target != null)
                    wakeUpMethod.SelectedItem = target.WakeUpMethod;
            }
        }

        private void destinationChanged(object sender, SelectionChangedEventArgs e)
        {
            var target = targetComputer.SelectedItem as TargetComputer;
            if (wakeUpMethod != null)
            {
                foreach (var method in wakeUpMethod.Items.OfType<WakeUpMethod>())
                    method.Target = target;
            }
        }

        private void createNewTarget(object sender, RoutedEventArgs e)
        {
            var target = new TargetComputer { Description = ".. Enter computer description here .." };
            TargetComputer.All.Add(target);
            targetComputer.Items.Refresh();
            targetComputer.SelectedItem = target;
        }

        private void createNewDestination(object sender, RoutedEventArgs e)
        {
            var destination = new ProxyWakeUpDestination();
            WakeUpDestination.All.Add(destination);
            wakeUpDestination.Items.Refresh();
            wakeUpDestination.SelectedItem = destination;
        }
    }
}
